package com.xuecheng.content.controller;

import com.xuecheng.api.content.CoursePubApi;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.service.CoursePubService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * <p>
 * 课程发布 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
@RequestMapping
public class CoursePubController implements CoursePubApi {

    @Autowired
    private CoursePubService  coursePubService;


    //课程预览
    @Override
    @GetMapping("course/preview/{courseId}/{companyId}")
    public Object previewCourse(@PathVariable Long courseId, @PathVariable Long companyId) {

        Map<String, Object> dataMap = coursePubService.previewCourse(courseId, companyId);

        // 1.使用视图和数据模型对象
        ModelAndView modelAndView = new ModelAndView("learing_article",dataMap);

        return modelAndView;
    }


    @Override
    @PostMapping("course_pub/publish/{courseId}")
    public void publish(@PathVariable Long courseId) {
        Long companyId = SecurityUtil.getCompanyId();

        coursePubService.publish(courseId,companyId);

    }
}
